package com.example.fzj.hazelcast.shiro;

import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

/**
 * @Author fanzj
 * @Date 2021/8/15 4:06 下午
 * @Version 3.0
 * @Description
 */
public class ShiroRealm extends AuthorizingRealm {

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        SimpleAuthorizationInfo simpleAuthorizationInfo=new SimpleAuthorizationInfo();
        return simpleAuthorizationInfo;
    }



    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        UsernamePasswordToken usernamePasswordToken= (UsernamePasswordToken) authenticationToken;
        AccountInfo accountInfo=new AccountInfo();
        accountInfo.setAccountName("admin");
        accountInfo.setAccPwd("bonree");
        // TODO VALID STORE DATA

        // return and rollback-exception
        SimpleAuthenticationInfo simpleAuthenticationInfo=new SimpleAuthenticationInfo(accountInfo,accountInfo.getAccPwd(),getName());
        return simpleAuthenticationInfo;
    }
}
